import request from "@/utils/request";
import { StoreForm } from "./types";
import { AxiosPromise } from "axios";
import {StorePageVO, StoreQuery} from "@/api/store/types";

/**
 * 店铺分页数据
 *
 * @param queryParams
 */
export function getStorePage(
	queryParams: StoreQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/store/page',
		method: 'get',
		params: queryParams
	});
}

/**
 * 获取店铺列表数据
 *
 * @param queryParams
 */
export function getByStoreKey(storeKey: string): AxiosPromise<[]> {
	return request({
		url: '/api/v1/store/list/storeKey/' + storeKey,
		method: 'get'
	});
}

/**
 * 获取所有店铺数据
 *
 * @param queryParams
 */
export function listAll(): AxiosPromise<[]> {
	return request({
		url: '/api/v1/store/list/all',
		method: 'get'
	});
}

/**
 * 获取店铺表单数据
 *
 * @param queryParams
 */
export function getStoreForm(storeId: number): AxiosPromise<StoreForm> {
	return request({
		url: '/api/v1/store/' + storeId + '/form',
		method: 'get'
	});
}

/**
 * 保存店铺
 *
 * @param data
 */
export function saveStore(data: StoreForm) {
  return request({
    url: "/api/v1/store",
    method: "post",
    data: data,
  });
}

/**
 * 删除店铺
 *
 * @param ids
 */
export function deleteStores(ids: string) {
	return request({
		url: '/api/v1/store/' + ids,
		method: 'delete'
	});
}

/**
 * 禁用店铺
 *
 * @param ids
 */
export function disableStores(ids: string) {
	return request({
		url: '/api/v1/store/disable/' + ids,
		method: 'get'
	});
}

/**
 * 启用店铺
 *
 * @param ids
 */
export function enableStores(ids: string) {
	return request({
		url: '/api/v1/store/enable/' + ids,
		method: 'get'
	});
}

/**
 * 导出店铺
 *
 * @param ids
 * @returns
 */
export function exportStore(ids: any) {
	return request({
		url: '/api/v1/store/_export?ids='+ids,
		method: 'get',
		responseType: 'arraybuffer'
	});
}

/**
 * 导入店铺
 *
 * @param file
 */
export function importStore(file: any) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/store/_import',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}
